package com.fuyao.cloud.admin.flow.service.flowable.impl;

import cn.hutool.core.collection.CollUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.fuyao.cloud.admin.flow.mapper.IFlowableActHiActinstMapper;
import com.fuyao.cloud.admin.flow.model.FlowableActHiActinst;
import com.fuyao.cloud.admin.flow.service.flowable.IFlowableActHiActinstService;
import org.flowable.bpmn.model.BaseElement;
import org.flowable.bpmn.model.SequenceFlow;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.stream.Collectors;

@Service
public class IFlowableActHiActinstServiceImpl extends ServiceImpl<IFlowableActHiActinstMapper, FlowableActHiActinst> implements IFlowableActHiActinstService {

    @Override
    public boolean deleteActHiAct(String processInstanceId, String sequenceFlow, List<SequenceFlow> resultList) {
        if(CollUtil.isEmpty(resultList)){
            return Boolean.FALSE;
        }
        List<String> stringList = resultList.stream().map(BaseElement::getId).collect(Collectors.toList());
        LambdaQueryWrapper<FlowableActHiActinst> queryWrapper = Wrappers.<FlowableActHiActinst>lambdaQuery().
                eq(FlowableActHiActinst::getProcInstId, processInstanceId).
                eq(FlowableActHiActinst::getActType, sequenceFlow)
                .in(FlowableActHiActinst::getActId, stringList);
        return super.remove(queryWrapper);
    }
}
